#include "display.h"
#include "delay.h"

sbit H1 = P1^0;	// H1位选 给高电平表示选中
sbit H2 = P1^6;	// H2位选

sbit a 	= P1^4;	
sbit b 	= P1^1;
sbit c 	= P0^1;
sbit d 	= P1^5;
sbit e 	= P0^2;
sbit f 	= P1^3;
sbit g 	= P1^2;
sbit dp = P1^7;

//#if DIG_PLACE_SELECT
//	unsigned char code DIG_PLACE[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};	//位选控制 阳极接法
//#else
//	unsigned char code DIG_PLACE[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};	//位选控制 阴极接法
//#endif

#if DIG_CODE_SELECT	
	unsigned char code DIG_CODE[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
										//0 1 2 3 4 5 6 7 8 9的段码 共阳极接法
#else
	unsigned char code DIG_CODE[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
										//0 1 2 3 4 5 6 7 8 9的段码 共阴极接法
#endif
									
unsigned char DisplayData[2]={0};	//存放要显示的段码

/*******************************************************************************
* 函数名         : DigDisplay
* 功能		  	 : 数码管动态显示
* 输入			 ：时间0 - 60秒
* 输出			 : 无
*******************************************************************************/

void DigDisplay(int m)
{
	unsigned char i;
	unsigned char j;
	
	DisplayData[0] = DIG_CODE[m%10];		//得到个位段码
	DisplayData[1] = DIG_CODE[m/10];		//得到十位段码
	
	for(i = 0; i < 2;i++)
	{
		/* 位选控制 */
		H1 = i;
		H2 = !i;
		
		/* 对段码进行解码 */
		a = (DisplayData[i] >> 0) & 0x01;
		b = (DisplayData[i] >> 1) & 0x01;
		c = (DisplayData[i] >> 2) & 0x01;
		d = (DisplayData[i] >> 3) & 0x01;
		e = (DisplayData[i] >> 4) & 0x01;
		f = (DisplayData[i] >> 5) & 0x01;
		g = (DisplayData[i] >> 6) & 0x01;

		dp = 1;			// dp 默认不亮
		
		/* 消隐 */
		j = 40;
		while(j--);
		a = 1;
		b = 1;
		c = 1;
		d = 1;
		e = 1;
		f = 1;
		g = 1;
			
	}
	
//	for(i=0; i<8; i++)
//	{
//		
//		GPIO_PLACE = DIG_PLACE[i];	 	//输出位选
//		GPIO_DIG = DisplayData[i];     	//输出段码
//		
//		j = 40;
//		while(j--);
//		GPIO_DIG = 0x00;			//消隐
//	}
}